home *** CD-ROM | disk | FTP | other *** search
- Path: gambier.ugrad.cs.ubc.ca!not-for-mail
- From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
- Newsgroups: comp.lang.c
- Subject: Re: Fractals
- Date: 5 Mar 1996 13:31:12 -0800
- Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
- Message-ID: <4hibr0INN7s1@gambier.ugrad.cs.ubc.ca>
- References: <4hhv43$49i@sunburst.ccs.yorku.ca>
- NNTP-Posting-Host: gambier.ugrad.cs.ubc.ca
-
- In article <4hhv43$49i@sunburst.ccs.yorku.ca>,
- Naftali Sturm <yu114405@yorku.ca> wrote:
- >How do you program fractals in C?
-
- You define a data type that can hold complex numbers. You can make it an
- abstract data type if you wish.
-
- Then you define some basic operations: complex multiplication, addition,
- norm and so forth.
-
- Then you compute the fractal using whatever iterative formula you wish, such as
-
- z = z^2 + C
-
- Where z is a complex number (x + iy), C is an arbitrary complex constant.
-
- You look at how fast that grows for various choices of x, which gives you your
- fractal 'hills' that you can represent as a colored ``topological map'', where
- the color at (x,y) represents the rate of growth of the iterated calculation
- for the initial value z = x + iy. Other formulae are possible.
-
- For example, if you use Newton's method to find the complex root of three, and
- use z as your initial approximation, and then assign one of three colors
- to (x,y) based on which of three roots Newton's method converges to with that
- starting value, you will end up with a three-colored fractal image.
-
-
- One possible representation of a complex number can be:
-
- typedef struct {
- double real;
- double imag;
- } complex_t;
-
- Then you define macros and functions for doing operations on the complex type.
- If you go far enough, you may even end up implementing complex transcendental
- functions, such as complex sine and cosine.
-
- The GNU C compiler has a native complex type, but this is not part of the
- standard C language.
- --
-
-